import { Component, OnInit } from '@angular/core';
import { Leave, Attendance, Money } from 'src/app/executiveStaff/dataDomain';
import { MONEY } from 'src/app/executiveStaff/data';
import {ServiceLogicService} from '../../service/service-logic.service';

@Component({
  selector: 'app-salary-statistic',
  templateUrl: './salary-statistic.component.html',
  styleUrls: ['./salary-statistic.component.css']
})
export class SalaryStatisticComponent implements OnInit {

  leave:Leave[];
  leavee:Leave[];
  attend : Attendance[];

  cutpayee:Money[];
  //cutpayee01=MONEY;
  cut_pay:Money[];

  admin_no : string;
  admin_id : string;
  start_time : string;
  flag = 0;
  
  constructor(private myService:ServiceLogicService) { }
  ngOnInit() {
    this.myService.getAllEmployeeLeaveRecord().then(res=>this.leavee=res);
    this.myService.getAllEmployeeLeaveRecord().then(res=>this.leave=res);
    this.myService.getAllAttendanceRecords().then(res=>this.attend=res);
  }

  srt():void{
    this.flag=1;
    this.leave = [];
    this.cutpayee=MONEY;
    this.cut_pay=[];
    this.start_time = (document.getElementById("start_time") as HTMLInputElement).value;
    this.admin_no = (document.getElementById("type") as HTMLInputElement).value;
    this.admin_id = (document.getElementById("admin_id") as HTMLInputElement).value;

   // for(let n of this.cutpayee01){
    //  this.cutpayee.push(n);
   // }
   for(let n of this.cutpayee){
     n.cutpay=0;
   }

    if(this.admin_id==""){
        if(this.admin_no=='0'){
          if(this.start_time=="")
            {
              alert('请输入查询参数');
              window.location.reload();
            }
          else{
         // this.flag=2;
          for(let tpLeave of this.leavee){
            //let te = tpLeave.satrt_time.split("/");
            //tpLeave.satrt_time = te[0]+te[1];
            //if(this.start_time==tpLeave.satrt_time)
            // tpLeave.satrt_time.replace("/","");
            if( tpLeave.satrt_time.includes((this.start_time)))
            {
              //this.flag=7;
              this.leave.push(tpLeave);
            }
            else{
            continue;
            }
          }
        }
        }
        else{
        //  this.flag=3;
          for(let tpLeave of this.leavee){
            //let te = tpLeave.satrt_time.split("/");
            //tpLeave.satrt_time = te[0]+te[1];
            //if(this.start_time==tpLeave.satrt_time)
           // tpLeave.satrt_time.replace("/","");
            for(let att of this.attend){
            if( tpLeave.satrt_time.includes((this.start_time))
            && this.admin_no==att.dept_no && tpLeave.admin_id==att.admin_id )
            this.leave.push(tpLeave);
            else
            continue;
            }
          }
        }
    }

    else{
     // this.flag=4;
      for(let tpLeave of this.leavee){
        //let te = tpLeave.satrt_time.split("/");
        //tpLeave.satrt_time = te[0]+te[1];
        //if(this.start_time==tpLeave.satrt_time)
       // tpLeave.satrt_time.replace("/","");
        if(this.admin_id==tpLeave.admin_id && tpLeave.satrt_time.includes((this.start_time)))
        this.leave.push(tpLeave);
        else
        continue;
      }
    }
  //  this.flag=10;
    for(let n of this.leave){
     // this.flag=2;
      for(let cut of this.cutpayee){
        if(n.type==0||n.type==1){
          if(cut.admin_id==n.admin_id){
            cut.cutpay = cut.cutpay-10;
          }
          else
          continue;
        }
        else if(n.type==2){
          if(cut.admin_id==n.admin_id){
            cut.cutpay = cut.cutpay-30;
          }
          else
          continue;
        }
        else
        continue;
      }
    }
    for(let n of this.cutpayee){
      this.cut_pay.push(n);
    }
    this.cutpayee=[];
  }
}
